﻿using OneWeb.Repository;
using OneWeb.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OneWeb.Controllers
{
    [RoutePrefix("author")]
    public class AuthorController : Controller
    {
        private AuthorRepository repository = new AuthorRepository();

        // GET: Author
        public ActionResult Index()
        {
            return View();
        }

        // GET: Author/Details/5
        [Route("details")]
        public ActionResult Details(int? id)
        {
            AuthorDetailViewModel viewModel = new AuthorDetailViewModel();
            if (id == null)
            { 
                throw new HttpException(404, "Not Found");
            }
            else
            {
                viewModel.Author = repository.Get((int)id);
            }
            return View(viewModel);
        }

        //// GET: Author/Create
        //public ActionResult Create()
        //{
        //    return View();
        //}

        //// POST: Author/Create
        //[HttpPost]
        //public ActionResult Create(FormCollection collection)
        //{
        //    try
        //    {
        //        // TODO: Add insert logic here

        //        return RedirectToAction("Index");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}

        //// GET: Author/Edit/5
        //public ActionResult Edit(int id)
        //{
        //    return View();
        //}

        //// POST: Author/Edit/5
        //[HttpPost]
        //public ActionResult Edit(int id, FormCollection collection)
        //{
        //    try
        //    {
        //        // TODO: Add update logic here

        //        return RedirectToAction("Index");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}

        //// GET: Author/Delete/5
        //public ActionResult Delete(int id)
        //{
        //    return View();
        //}

        //// POST: Author/Delete/5
        //[HttpPost]
        //public ActionResult Delete(int id, FormCollection collection)
        //{
        //    try
        //    {
        //        // TODO: Add delete logic here

        //        return RedirectToAction("Index");
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}

        //protected override void OnException(ExceptionContext filterContext)
        //{

        //}
    }
}
